<html>
<head>
    <title>流程基本信息列表</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <script src="../../static/bootstrap/js/jquery-3.4.1.min.js" type="text/javascript"></script>
    <script src="../../static/bootstrap/js/static-resources.js"></script>
</head>
<script type="text/javascript">
    $(function () {
        $(".footerPage").load("../footer.html");
        let DEFAULT_DATA_MODEL = {
            "bpmId":"",
            "bpmName":"",
            "equallyTaskAmount":"",
            "isRunAgain":"",
            "subsCode":"",
            "createUser":"",
            "createTime":"",
            "lastUpdateUser":"",
            "lastUpdateTime":"",
        };
        new Vue({
            el : '#app',
            mixins: [window.$DEFAULT_MIXIN],
            data: {
                queryParam: {
                    bpmId: "",
                },
                pageInfo: {
                    page: 1,
                    size: 10,
                    total: 0
                },
                list:[],
                selected: null,
                show: false,
                show2:false,
                readonly: false,
                loading: false,
                modelTitle:"",
                dataObj: {},
                opType: "",
            },
            watch:{
                opType(val, old){
                    if (val == "add") {
                        this.modelTitle = "流程基本信息表新增";
                        this.show2 = true;
                        this.readonly = false;
                        this.dataObj = $.extend({}, DEFAULT_DATA_MODEL);
                    } else if (val == "update") {
                        this.modelTitle = "流程基本信息表修改";
                        this.show = true;
                        this.readonly = false;
                        this.dataObj = $.extend({}, this.selected);
                    } else if (val == "view") {
                        this.modelTitle = "流程基本信息表详情";
                        this.show = true;
                        this.readonly = true;
                        this.dataObj = $.extend({}, this.selected);
                    }
                }
            },
            computed:{
                S_SUBS_DS_TYPE(){
                    return S_SUBS_DS_TYPE;
                },
                STD_PUB_YN(){
                    return STD_PUB_YN;
                },
                BPM_TYPE(){
                    return BPM_TYPE;
                },
                paths(){
                    return [
                        {text: '首页', href: '/index.html'},
                        {text: '系统管理', href: '#'},
                        {text: '系统设置', href: '#'},
                        {text: '流程基本信息列表', href: 'batch-console/BpmBaseInfoList.html'},
                    ]
                },
                fields(){
                    return [
                        {key:"bpmId", label:"流程标识", sortable: false},
                        {key:"bpmName", label:"流程名称", sortable: false},
                        {key:"equallyTaskAmount", label:"任务并发数", sortable: false},
                        {key:"isRunAgain", label:"是否允许重跑", sortable: false,
                            formatter: function (value, key, item) {
                                return formatter_STD_PUB_YN(value)
                            }    
                        },
                        {key:"subsCode", label:"子系统代码", sortable: false},
                        {key:"createUser", label:"创建人", sortable: false},
                        {key:"createTime", label:"创建时间", sortable: false},
                        {key:"lastUpdateUser", label:"最后更新人", sortable: false},
                        {key:"lastUpdateTime", label:"最后修改时间", sortable: false},
                        
                    ]
                },
            },
            methods:{
                onRowSelected(items){
                    this.selected = items[0];
                },
                submitQry(page){
                    if (page == true) {
                        this.pageInfo.page = 1;
                    }
                    var self = this;
                    JLEUtil.requestForm("api/bpm/base/infos/2", "POST", null, $.extend({}, self.queryParam, self.pageInfo),
                        function(data, textStatus, jqXHR){
                            self.list = data.rows;
                            self.pageInfo.total = data.total;
                        },
                        function(jqXHR, textStatus, errorThrown){
                        });
                },
                resetContent(){
                    this.queryParam.bpmId = "";
                },
                toAddPage(){
                    this.$bvModal.show('bv-modal-example1');
                    this.opType = "add";
                },
                toModifyRecord(){
                    if (!this.selected) {
                        this.$bvToast.toast(`请选择一行数据`, {
                            title: '提示 ',
                            toaster: 'b-toaster-top-center',
                            solid: true
                        });
                        return;
                    }
                    this.$bvModal.show('bv-modal-example');
                    this.opType = "update";
                },
                delRecord(){
                    if (!this.selected) {
                        this.$bvToast.toast(`请选择一行数据`, {
                            title: '提示 ',
                            toaster: 'b-toaster-top-center',
                            solid: true
                        });
                        return;
                    }
                    let self = this;
                    this.$bvModal.msgBoxConfirm(`你确定要删除【${this.selected.bpmName}】这个审批流程?`, {
                        title: '删除提示',
                        size: 'sm',
                        buttonSize: 'sm',
                        okVariant: 'success',
                        headerClass: 'p-2 border-bottom-0',
                        footerClass: 'p-2 border-top-0',
                        cancelTitle: "取消",
                        okTitle: "确定",
                        centered: true
                    }).then(value => {
                        if (!value) return;
                    JLEUtil.request("api/bpm/base/info", "DELETE", null,
                        {
                            bpmId : this.selected.bpmId,
                        },
                        function(data, textStatus, jqXHR){
                            self.$bvToast.toast(`记录删除成功！`, {
                                title: '提示 ',
                                toaster: 'b-toaster-top-center',
                                solid: true
                            });
                            self.submitQry(true);
                        },
                        function(jqXHR, textStatus, errorThrown){

                        });
                })
                },
                toViewPage(){
                    if (!this.selected) {
                        this.$bvToast.toast(`请选择一行数据`, {
                            title: '提示 ',
                            toaster: 'b-toaster-top-center',
                            solid: true
                        });
                        return;
                    }
                    this.$bvModal.show('bv-modal-example');
                    this.opType = "view";
                },
                handlePath(event){
                    let url = $(event.target).attr('href');
                    window.$TOP.go(url)
                },

                saveInfo(){

                    let requestOptions = {
                        url : "api/bpm/base/info",
                        type : "POST",
                        dataObj: this.dataObj,
                        success: (data)=>{
                        this.$bvToast.toast(data.message, {
                        title: '提示 ',
                        toaster: 'b-toaster-top-center',
                        solid: true
                    });
                    this.loading = false;
                    this.closeModel();
                    this.submitQry();
                },
                    error: (jqXHR, textStatus, errorThrown)=>{
                        this.loading = false;
                        this.$bvToast.toast("提交失败", {
                            title: '提示 ',
                            toaster: 'b-toaster-top-center',
                            solid: true
                        });
                    }
                };
                    if (this.opType == "add") {
                        requestOptions.type = "POST";
                    } else if (this.opType == "update") {
                        requestOptions.type = "PUT";
                    }

                    this.loading = true;
                    let self = this;
                    this.$refs.form.validate().then(success => {
                        if (!success) {
                        this.loading = false;
                        return;
                    }
                    JLEUtil.request(requestOptions.url, requestOptions.type, null,
                        requestOptions.dataObj,
                        requestOptions.success,
                        requestOptions.error
                    );
                });
                },
                toEdit(){
                    if(!this.selected){
                        this.$bvToast.toast(`请选择一行数据`, {
                            title: '提示 ',
                            toaster: 'b-toaster-top-center',
                            solid: true
                        });
                        return;
                    }
                    var bpmid = this.selected.bpmId;
                    var url = `AutoBpmBaseInfoUpdateNewTab.html?&bpmId=${bpmid}`;
                    var commonLinkObj = document.getElementById("commonLink");
                    if(!commonLinkObj){
                        commonLinkObj = document.createElement("a");
                        commonLinkObj.target = "_blank";
                    }
                    commonLinkObj.href = url;
                    commonLinkObj.click();
                },
                closeModel(){
                    this.show = false;
                    this.show2 = false;
                    this.modelData = {};
                    this.opType = "";
                }
            },
            toPublish(){
                // var row = $('#dg').datagrid('getSelected');
                if (this.selected) {
                    if("1" == this.selected.bpmState){
                        this.$bvToast.toast(`所选流程已经发布!`, {
                            title: '提示 ',
                            toaster: 'b-toaster-top-center',
                            solid: true
                        });
                        return;
                    }
                    this.$bvModal.msgBoxConfirm(`确定要发布自动流程?`, {
                        title: '提示',
                        size: 'sm',
                        buttonSize: 'sm',
                        okVariant: 'success',
                        headerClass: 'p-2 border-bottom-0',
                        footerClass: 'p-2 border-top-0',
                        cancelTitle: "取消",
                        okTitle: "确定",
                        centered: true
                    }).then(value => {
                        if (!value) return;
                    let self = this;
                    JLEUtil.request("api/bpm/base/publish", "POST", null,self.selected,
                        function(data, textStatus, jqXHR){
                            self.$bvToast.toast(`发布成功！`, {
                                title: '提示 ',
                                toaster: 'b-toaster-top-center',
                                solid: true
                            });
                            self.submitQry(true);
                        },
                        function(jqXHR, textStatus, errorThrown){

                        });
                })
                } else {
                    this.$bvToast.toast(`请选择一行数据`, {
                        title: '提示 ',
                        toaster: 'b-toaster-top-center',
                        solid: true
                    });
                    return;
                }
            },
            mounted(){
                this.submitQry(true);
            }
        })
    });

</script>
</head>
<body>
<div class="headerPage"></div>
<div id="app">
    <div class="container-fluid mt-3">
        <div class="row">
            <div class="col-sm-12 search-box">
                <form role="form" style="text-align: right"  id="formData" class="row">
                    <div class="form-group col-sm-4">
                        <b-form-group label-cols="4" label-cols-lg="4" label="流程标识：" >
                            <b-form-input size="sm" v-model="queryParam.bpmId"></b-form-input>
                        </b-form-group>
                    </div>
                    <div class="control-group col-sm-2">
                        <div class="text-center">
                            <b-button variant="primary" @click="submitQry(true)">&nbsp;&nbsp;查&nbsp;&nbsp;询&nbsp;&nbsp;</b-button>
                            <b-button variant="secondary" @click="resetContent">&nbsp;&nbsp;重&nbsp;&nbsp;置&nbsp;&nbsp;</b-button>
                        </div>
                    </div>
                </form>
                <div class="row"></div>
                <!-- table -->
            </div>
            <div class="form-group col-sm-12 ">
                <div class="text-left">
                    <b-button variant="primary" @click="toAddPage">新增审批流程</b-button>
                    <b-button variant="primary" @click="toEdit">配置审批流程</b-button>
                    <b-button variant="primary" @click="doPublish">发布审批流程</b-button>
                    <b-button variant="primary" @click="toModifyRecord">&nbsp;&nbsp;&nbsp;修&nbsp;&nbsp;&nbsp;改&nbsp;&nbsp;&nbsp;</b-button>
                    <b-button variant="primary" @click="delRecord">&nbsp;&nbsp;&nbsp;删&nbsp;&nbsp;&nbsp;除&nbsp;&nbsp;&nbsp;</b-button>
                    <b-button variant="primary" @click="toViewPage">&nbsp;&nbsp;&nbsp;查&nbsp;&nbsp;&nbsp;看&nbsp;&nbsp;&nbsp;</b-button>
                </div>
            </div>
        </div>
    </div>
    <div class="container-fluid">
        <!-- table start -->
        <b-table responsive hover selectable bordered fixed striped small
                 @row-selected="onRowSelected"
                 selected-variant="primary"
                 select-mode="single" :fields="fields" :items="list" >
            <template v-slot:table-colgroup="scope">
                <col
                        v-for="field in scope.fields"
                        :key="field.key"
                        :style="{ width: '180px' }"
                >
            </template>
            <template v-slot:cell()="data" >
                <div class="text-truncate">{{ data.value }}</div>
            </template>
        </b-table>
        <div class="float-right">
            <b-pagination
                    v-model="pageInfo.page"
                    :total-rows="pageInfo.total"
                    :per-page="pageInfo.size"
                    @change="submitQry"
            ></b-pagination>
        </div>
        <!-- table end -->
    </div>

    <b-modal  v-model="show2" id="bv-modal-example1" :title="modelTitle" size="xl"
              scrollable
              no-close-on-backdrop
              no-close-on-esc>
        <b-container fluid>
            <validation-observer ref="form">
                <form role="form" >
                    <div class="row">
                        <div class="col-sm-6">
                            <validation-provider name="bpmType" :rules="{ required: true }" v-slot="validationContext">
                                <b-form-group label="流程类型" label-cols-sm="4" label-align-sm="right">
                                    <b-form-select type="text" v-model="dataObj.bpmType=2"   name="state" placeholder="流程类型"  :disabled="1==1"
                                                   :options="BPM_TYPE"
                                                   value-field="enname" text-field="cnname" ></b-form-select>
                                </b-form-group>
                            </validation-provider>
                        </div>
                        <div class="col-sm-6">
                            <validation-provider name="bpmName" :rules="{ required: true }" v-slot="validationContext">
                                <b-form-group label="流程名称" label-cols-sm="4" label-align-sm="right">
                                    <b-form-input type="text" v-model="dataObj.bpmName"
                                                  :state="getValidationState(validationContext)"
                                                  name="bpmName" placeholder="流程名称"  :readonly="readonly"></b-form-input>
                                    <b-form-invalid-feedback >流程名称不能为空</b-form-invalid-feedback>
                                </b-form-group>
                            </validation-provider>
                        </div>
                        <div class="col-sm-6">
                            <b-form-group label="是否允许重跑" label-cols-sm="4" label-align-sm="right">
                                <b-form-select type="text" v-model="dataObj.isRunAgain" name="state" placeholder="是否允许重跑"  :disabled="readonly"
                                               :options="STD_PUB_YN"
                                               value-field="enname" text-field="cnname"></b-form-select>
                            </b-form-group>
                        </div>
                    </div>
                </form>
            </validation-observer>
        </b-container>
        </b-container>
        <template v-slot:modal-footer>
            <div class="control-group col-sm-12">
                <div class="text-center">
                    <b-button variant="primary" @click="saveInfo" :disabled="loading">
                        <div v-if="loading">
                            <b-spinner small></b-spinner>
                            保存中...
                        </div>
                        <span v-else="loading">保存</span>
                    </b-button>
                    <b-button variant="secondary" @click="closeModel" :disabled="loading">返回</b-button>
                </div>
            </div>
        </template>
    </b-modal>

    <b-modal  v-model="show" id="bv-modal-example" :title="modelTitle" size="xl"
              scrollable
              no-close-on-backdrop
              no-close-on-esc>
        <b-container fluid>
            <validation-observer ref="form">
                <form role="form" >
                    <div class="row">
                        <div class="col-sm-6">
                            <validation-provider name="bpmId" :rules="{ required: true }" v-slot="validationContext">
                                <b-form-group label="流程标识" label-cols-sm="4" label-align-sm="right">
                                    <b-form-input type="text" v-model="dataObj.bpmId" :readonly="opType != 'add' || readonly"
                                                  :state="getValidationState(validationContext)"
                                                  name="bpmId" placeholder="流程标识"></b-form-input>
                                    <b-form-invalid-feedback >代码不能为空</b-form-invalid-feedback>
                                </b-form-group>
                            </validation-provider>
                        </div>
                        <div class="col-sm-6">
                            <validation-provider name="bpmName" :rules="{ required: true }" v-slot="validationContext">
                                <b-form-group label="子系统名称" label-cols-sm="4" label-align-sm="right">
                                    <b-form-input type="text" v-model="dataObj.bpmName"
                                                  :state="getValidationState(validationContext)"
                                                  name="bpmName" placeholder="流程名称"  :readonly="readonly"></b-form-input>
                                    <b-form-invalid-feedback >数据源代码不能为空</b-form-invalid-feedback>
                                </b-form-group>
                            </validation-provider>
                        </div>
                        <div class="col-sm-6">
                            <b-form-group label="任务并发数" label-cols-sm="4" label-align-sm="right">
                                <b-form-input type="text" v-model="dataObj.equallyTaskAmount" name="equallyTaskAmount" placeholder="任务并发数"  :readonly="readonly"></b-form-input>
                            </b-form-group>
                        </div>
                        <div class="col-sm-6">
                            <b-form-group label="是否允许重跑" label-cols-sm="4" label-align-sm="right">
                                <b-form-select type="text" v-model="dataObj.isRunAgain" name="state" placeholder="是否允许重跑"  :disabled="readonly"
                                               :options="STD_PUB_YN"
                                               value-field="enname" text-field="cnname"></b-form-select>
                            </b-form-group>
                        </div>
                        <div class="col-sm-6">
                            <b-form-group label="子系统代码" label-cols-sm="4" label-align-sm="right">
                                <b-form-input type="text" v-model="dataObj.subsCode" name="subsCode" placeholder="子系统代码"  :readonly="readonly"></b-form-input>
                            </b-form-group>
                        </div>
                        <div class="col-sm-6">
                            <b-form-group label="创建人" label-cols-sm="4" label-align-sm="right">
                                <b-form-input type="text" v-model="dataObj.createUser" name="createUser" placeholder="创建人"  :readonly="readonly"></b-form-input>
                            </b-form-group>
                        </div>
                        <div class="col-sm-6">
                            <b-form-group label="数据源类型" label-cols-sm="4" label-align-sm="right">
                                <b-form-select type="text" v-model="dataObj.createTime" name="state" placeholder="备用状态"  :disabled="readonly"
                                               :options="S_SUBS_DS_TYPE"
                                               value-field="enname" text-field="cnname"></b-form-select>
                            </b-form-group>
                        </div>
                    </div>
                </form>
            </validation-observer>
        </b-container>
        <template v-slot:modal-footer>
            <div class="control-group col-sm-12">
                <div class="text-center">
                    <b-button variant="primary" @click="saveInfo" :disabled="loading">
                        <div v-if="loading">
                            <b-spinner small></b-spinner>
                            保存中...
                        </div>
                        <span v-else="loading">保存</span>
                    </b-button>
                    <b-button variant="secondary" @click="closeModel" :disabled="loading">返回</b-button>
                </div>
            </div>
        </template>
    </b-modal>
</div>
<div class="footerPage"></div>
</body>
</html>
